import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import * as Updates from "expo-updates";
import { useEffect, useState } from "react";

export default function App() {



    const [testVal,setTestVal] = useState('')
    useEffect(() => {


        updateApp();
    }, []);

    async function updateApp() {
        try {
            const update = await Updates.checkForUpdateAsync();
            console.log('update',update)
            if (update.isAvailable) {
                await Updates.fetchUpdateAsync();
                // 强制应用重新加载以应用更新
                Updates.reloadAsync();
                setTestVal('得到了更新')
            }else{
                setTestVal('没有得到更新')

            }
        } catch (e) {
            // 在实际应用中，你应该处理错误情况
            console.error(e);
            setTestVal('更新失败'+e)

        }
    }


    return (
        <View style={styles.container}>
            <Text>Open up App.4444444</Text>
            <Text>Open up App.4444444</Text>
            <Text>Open up App.4444444</Text>
            <Text>Open up App.4444444</Text>
            <Text>Open up App.4444444</Text>
            <StatusBar style="auto" />
            <TouchableOpacity onPress={updateApp}>
                <Text>666666666-{testVal}</Text>
                <Text>8888888666----------888</Text>
            </TouchableOpacity>
        </View>
    );
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff',
        alignItems: 'center',
        justifyContent: 'center',
    },
});
